/*
 * @lc app=leetcode.cn id=605 lang=javascript
 *
 * [605] 种花问题
 */

// @lc code=start
/**
 * @param {number[]} flowerbed
 * @param {number} n
 * @return {boolean}
 */
var canPlaceFlowers = function(flowerbed, n) {
    for (let index = 0; index < flowerbed.length; index++) {
        const element = flowerbed[index];
        const pre = flowerbed[index - 1];
        const next = flowerbed[index + 1];
        if (!element && !pre && !next) {
            flowerbed[index] = 1
            n--
        }
    }
    return n <= 0
};
// @lc code=end

